<?php
    include_once('lang.php');
    $home_nav = '';
    $profile_nav = '';
    $project_nav = ' class="current"';
    $product_nav = '';
    $contact_nav = '';
    
    $project_0_nav = ' class="current"';
    $project_1_nav = '';
    $project_2_nav = '';
    $project_3_nav = '';
    $project_4_nav = '';
    $project_5_nav = '';
    
    $page_title = __l('project-all-title');
    
    include('header.php');
    include('function/function.php');
    
    $con = db_connect();
    
    // PAGE LIMIT
    if(isset($_GET['p'])){
	$page = $_GET['p'];
    }else{
	$page = 1;
    }
    
    $sql_relate = "SELECT * FROM projects ORDER BY project_id";
    
    $page_limit = 15;
    $start_row = (($page-1))*$page_limit;
    $sql_relate_nolimit = $sql_relate;
    $sql_relate .= " LIMIT $start_row,$page_limit";
    
    $count_row = mysql_query($sql_relate_nolimit);
    $count_row2 = mysql_num_rows($count_row);
    $count_row3 = ceil($count_row2/$page_limit) ;
    
    $prevPage = '&nbsp;';
    $nextPage = '&nbsp;';
    
    if($count_row3>1)
    {
	if($page>1){
	    $prevPage = '<a href="projects.php?p='.($page-1).'" title="'.__l('project-previous').'"><<< '.__l('project-previous').'</a>';
	}
	
	if($count_row3!=$page){
	    $nextPage = '<a href="projects.php?p='.($page+1).'" title="'.__l('project-next').'">'.__l('project-next').' >>></a>';
	}
    }
    
    //echo $prevPage,' ' ,$nextPage;
    // PAGE LIMIT END
    
    //$sql = "SELECT * FROM projects ORDER BY project_id";
    $result = mysql_query($sql_relate);
    
    if(mysql_num_rows($result)>=1){
    $project_lits = '';
    $project_box_list = '';
    while($row=mysql_fetch_assoc($result)){	
	$project_id = $row['project_id'];
	
	if($_SESSION['lang']=='th'){
	    $project_date = get_thai_date(date("F j Y",strtotime($row['project_date'])));
	}else{
	    $project_date = date("F j Y",strtotime($row['project_date']));
	}
	
	$project_detail_title = $row['project_title'];
	
	if($row['project_area']>0){
	    $project_area  = $row['project_area'];
	    $projectarea = __l('project-area');
	}else{
	    $project_area = __l('no-project-area');
	    $projectarea = '';
	}
	
	if(trim($row['project_owner'])!=''){
	    $project_owner  = $row['project_owner'];
	}else{
	    $project_owner  = __l('no-project-owner');
	}
	
	if(trim($row['project_complete_year'])!=''){
	    $project_complete_year  = $row['project_complete_year'];
	}else{
	    $project_complete_year  = __l('no-project-complete-year');
	}
	
	if($row['project_value']>0){
	    $project_value  = number_format($row['project_value'], 0, '.', ',');
	    $projectvalue = __l('project-value');
	}else{
	    $project_value = __l('no-project-value');
	    $projectvalue = '';
	}
	
	
	if($row['project_img']!='' && file_exists( "images/projects/".$row['project_id']."/big_".$row['project_img'])){
	    $img__ = $row['project_id'].'/big_'.$row['project_img'];
	}else if($row['project_img']!='' && file_exists( "images/projects/".$row['project_id']."/".$row['project_img'])){
	    $img__ = $row['project_id'].'/'.$row['project_img'];
	}else{
	    $img__ = 'no-pic.jpg';
	}
	
	if(file_exists('images/projects/'.$row['project_id'].'/'.$row['project_cert']) && trim($row['project_cert'])!=''){
	    $project_cert = '<a href="images/projects/'.$row['project_id'].'/'.$row['project_cert'].'" class="certColorBox"><img src="images/cert_bt_'.$_SESSION['lang'].'.png" alt="Certificate"/></a>';
	}else{
	    $project_cert = '';
	}
	
	$sql = "SELECT * FROM project_img WHERE project_id=$project_id AND project_img_show=1 ORDER BY img_position";
	$result2 = mysql_query($sql);
	$project_img_lits = '';
	$i = 1;
	if(mysql_num_rows($result2)>=1){
	    $project_img_lits .= '<ul class="project_r_thumb_list_ jcarousel-skin-tango">';
	    while($row2=mysql_fetch_assoc($result2)){
		if($i<2){
		    $thumb_active = ' thumb_active';
		    if(file_exists('images/projects/'.$project_id.'/'.$row2['project_img_path']) && trim($row2['project_img_path'])!=''){
			$img__ = $project_id.'/'.$row2['project_img_path'];
		    }
		}else{
		    $thumb_active = '';
		}
		
		if(file_exists('images/projects/'.$project_id.'/'.$row2['project_img_path']) && trim($row2['project_img_path'])!=''){
		    $project_img_lits .=<<<showcase_lits
			<li class="{$row2['project_img_id']}">
			    <img src="images/projects/{$project_id}/{$row2['project_img_path']}" alt="{$project_detail_title}" class="project_thumb_gallery{$thumb_active}" />
			</li>
showcase_lits;
		    $project_img_first = $project_id.'/'.$row2['project_img_path'];
		}else{
		    $project_img_lits .=<<<showcase_lits
			<li id="{$row2['project_img_id']}">
			    <img src="images/projects/{$project_id}/{$row2['project_img_path']}" alt="{$project_detail_title}" class="project_thumb_gallery{$thumb_active}" />
			</li>
showcase_lits;
		}
		$i++;
	    }
	    $project_img_lits .= '</ul>';
	}
	
	$projectareatitle = __l('project-area-title');
	$projectownertitle = __l('project-owner-title');
	$projectcompletetitle = __l('project-complete-title');
	$projectvaluetitle = __l('project-value-title');
	
	
	
	$project_box_list .= <<<project
	    <div class="project_all_box">
		<div class="project_l">
		    <table style="width:100%;">
			<tr>
			    <td style="vertical-align:middle;text-align:center;width:100%;height:260px;">
				<img src="images/projects/{$img__}" alt="{$project_detail_title}" class="project_img" />
			    </td>
			</tr>
		    </table>
		</div>
		<div class="project_r">
		    <div class="project_r_detail">
			<!--<p class="project_r_detail_date">{$project_date}  //</p>-->
			<h3 class="project_r_detail_title">{$project_detail_title}</h3>
			<p class="project_r_detail_">
			    <span class="span_owner-title">{$projectareatitle} : </span>{$project_area} {$projectarea}<br />
			    <span class="span_owner span_owner-title span_owner_{$lang}">{$projectownertitle} : </span><span class="owner-title">{$project_owner}</span><br />
			    <span class="span_owner-title">{$projectcompletetitle} : </span>{$project_complete_year}<br />
			    <span class="span_owner-title">{$projectvaluetitle} : </span>{$project_value} {$projectvalue}<br />
			</p>
			<div class="project_cert">{$project_cert}</div>
		    </div>
		    <div class="project_r_thumb">
			{$project_img_lits}
		    </div>
		</div>
		<div class="clear">&nbsp;</div>
	    </div>
project;
    }
?>
    <link rel="stylesheet" type="text/css" href="css/tango/skin.css" />
    <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
    <script>$(document).ready(function(){
            jQuery(".project_r_thumb_list_").jcarousel({
		scroll: 1,
		wrap: 'circular',
                itemFallbackDimension : 63
	    });
           
           $('.project_thumb_gallery').live('click',function(){
		var thisEle = $(this);
		thisEle.parent().parent().find('.project_thumb_gallery').removeClass('thumb_active');
		thisEle.addClass('thumb_active');
                thisEle.parent().parent().parent().parent().parent().parent().parent().parent().find('.project_img').attr('src',thisEle.attr('src'));
	    });
        });
    </script>
<?php
	echo $project_box_list;
?>
	<div id="projects_ctrl">
	    <div id="projects_prev"><?php echo $prevPage; ?></div>
	    <div id="projects_next"><?php echo $nextPage; ?></div>
	    <div class="clear">&nbsp;</div>
	</div>
<?php
    }else{
	echo '<div id="no_product">COMING SOON</div>';
    }
    include('footer.php');
?>